//
//  BloodOxygenProvider.swift
//  DaRings
//
//  Created by HFY on 2022/11/13.
//

import UIKit
import MYModule

open class BloodOxygenProvider: NSObject {
    
    public var date: Date?
    public var last: SingleBloodOxygenModel?
    public var sevenTimes: [SingleBloodOxygenModel]?
    
    public init(date: Date?) {
        super.init()
        
        guard let date = date else {
            return
        }
        
        self.date = date
        self.last = SingleBloodOxygenModel.last(from: date.timeIntervalSince1970)
        self.sevenTimes = sevenTimesData()
       
       
    }
    
    public init(bloodOxggenModel: SingleBloodOxygenModel?) {
        
        super.init()
        
        self.last = bloodOxggenModel
        self.date = last?.date
        self.sevenTimes = sevenTimesData()
    
    }
    
    open func sevenTimesData() ->[SingleBloodOxygenModel] {
        
        guard let last = last else {
            return (0 ..< 7).map { _ in SingleBloodOxygenModel() }
        }
        
        var sevenTimes = SingleBloodOxygenModel.sevenTimesModel(from: last.end)
        if sevenTimes.count < 7 {
            
          let emptyData = (sevenTimes.count ..< 7).map { _ in SingleBloodOxygenModel() }
            sevenTimes.append(contentsOf: emptyData)
        }
        
        /// 展示 是从右到 左
        return sevenTimes.reversed()
    }
    
    open var dateTitle: String {
        
        guard let last = last else { return "--" }
        let date = Date(timeIntervalSince1970: last.end)
        
        return date.localStringOfDateTime
        
    }
    

}
